export default {
    data() {
        return {
            radio: '1',
            value1: '',
            order_id:0,
            status_text:'',
            detail_data:'',
            return_price:''

        }
    },
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        if (that.$route.query.order_id) {
            that.order_id = that.$route.query.order_id;
        }
        if (that.$route.query.status_text) {
            that.status_text = that.$route.query.status_text;
        }
        that.detail()
    },
    methods: {
        rowClass({row, rowIndex}) {
            return 'background:#f5f7fa;border-right:0;'
        },
        cellStyle({row, column, rowIndex, columnIndex}) {
            if (rowIndex === 1 && columnIndex === 2) { //指定坐标
                return 'background:pink'
            } else {
                return ''
            }
        },

        /**
         * 加载详情
         */
        detail: function () {
            let that = this;
            //请求的数据
            let formData = {};
            formData.token = that.token;
            formData.order_id = that.order_id;
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/api/order/order_settlement", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.detail_data = res.body;
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 退款
         */
        sendRefund:function () {
            let that = this;
            if(that.return_price === ''){
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请输入退款金额' }`
                });
                return false;
            }
            if(that.return_price > that.detail_data.pay_price){
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '退款金额不能大于实付金额' }`
                });
                return false;
            }
            if(that.value1 === ''){
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请选择最后退款时间' }`
                });
                return false;
            }
            let formData = {};
            formData.token = that.token;
            formData.order_id = that.order_id;
            formData.return_price = that.return_price;
            formData.refund_type = that.radio;
            formData.refund_period = that.formatDateTime(that.value1);
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/api/order/wx_refund", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    that.$router.back(-1);
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        //时间转换
        formatDateTime: function(date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            var minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;
            return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
        },

        /**
         * 返回上一页
         */
        canelOrder:function () {
            let that = this;
            that.$router.back(-1);
        }
    }
}